package cn.com.czpb.client.utils;

import android.util.Log;

/**
 * Created by 猪猪侠 on 2017/6/27.
 */

public class LogUtils {
    private static final String TAG = "LogUtils";
    public static final int VERBOSE=1;

    public static final int DEBUG=2;

    public static final int INFO=3;

    public static final int WARN=4;

    public static final int ERROR=5;

    public static final int NOTHING=6;

    //设置日志等级
    public static int level = VERBOSE;

    public static String customTagPrefix = "";
    private static String generateTag(StackTraceElement caller) {
        String tag = "%s.%s(L:%d)";
        String callerClazzName = caller.getClassName();
        callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
        tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
        tag = StringUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
        return tag;
    }

    public static void v(String msg){
        StackTraceElement caller = Thread.currentThread().getStackTrace()[4];
        String tag = generateTag(caller);
        if (level<=VERBOSE){
            Log.v(tag,msg);
        }
    }
    public static void d(String msg){
        StackTraceElement caller = Thread.currentThread().getStackTrace()[4];
        String tag = generateTag(caller);
        if (level<=DEBUG){
            Log.d(tag,msg);
        }

    }
    public static void i(String msg){
        StackTraceElement caller = Thread.currentThread().getStackTrace()[4];
        String tag = generateTag(caller);
        if (level<=INFO){
            Log.i(tag,msg);
        }

    }
    public static void w(String msg){
        StackTraceElement caller = Thread.currentThread().getStackTrace()[4];
        String tag = generateTag(caller);
        if (level<=WARN){
            Log.w(tag,msg);
        }

    }
    public static void e(String msg){
        StackTraceElement caller = Thread.currentThread().getStackTrace()[4];
        String tag = generateTag(caller);
        if (level<=ERROR){
            Log.e(tag,msg);
        }

    }

    public static void v(String tag,String msg){
        if (level<=VERBOSE){
            Log.v(tag,msg);
        }
    }
    public static void d(String tag,String msg){
        if (level<=DEBUG){
            Log.d(tag,msg);
        }

    }
    public static void i(String tag,String msg){
        if (level<=INFO){
            Log.i(tag,msg);
        }

    }
    public static void w(String tag,String msg){
        if (level<=WARN){
            Log.w(tag,msg);
        }

    }
    public static void e(String tag,String msg){
        if (level<=ERROR){
            Log.e(tag,msg);
        }

    }

}
